package com.myjunjie.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.JsonObject;
import com.myjunjie.blog.service.IArticleService;
import com.myjunjie.blog.service.impl.ArticleServiceImpl;

/**
 * Servlet implementation class GetArticleByIdServlet
 */
@WebServlet("/GetArticleByIdServlet")
public class GetArticleByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	public void init() throws ServletException {

	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");

		//获取参数
		String id = request.getParameter("id");
		
		// 调用服务
		IArticleService articleService = new ArticleServiceImpl();
		JsonObject object = articleService.getArticleById(id);

		//返回结果
		PrintWriter out = response.getWriter();
		out.println(object);
	}

	public void destroy() {

	}

}
